package holiday_demo;

import java.util.ArrayList;
import java.util.Random;

public class ArrayListReturn {
    //用一个大集合存入20个随机数字，然后筛选其中的偶数元素，放到小集合中


    public static void main(String[] args) {
        ArrayList<Integer> bigNum=new ArrayList<>();
        ArrayList<Integer> smallNum=new ArrayList<>();
        Random ran_num=new Random();
        //为大集合存入随机数字
        for (int i = 0; i <20; i++) {
            bigNum.add(ran_num.nextInt(100));
        }

        ArrayListReturn.printSmillArrayList(bigNum,smallNum);
    }
    public static void printSmillArrayList(ArrayList<Integer> list,ArrayList<Integer> small){
        //筛选
        for (int textNum : list) {
            if (textNum % 2 == 0)
                small.add(textNum);
        }
        //打印出小集合的元素
        System.out.println("小集合的长度为："+small.size());
        for (Integer element:small) {
            System.out.print(element+"  ");
        }
    }
}
